#include "kernel.h"
unsigned int icmp_checksum_loc;
unsigned int icmp_checksum;
unsigned int icmp_len;

void ICMP(unsigned char *packet, unsigned int *len, unsigned int type, unsigned int code, unsigned long cksum, unsigned long id, unsigned long seq) {
	
	int i;
        pack_1_byte(packet, type);
        pack_1_byte(packet, code);
	icmp_checksum_loc = packet_len;
        pack_2_bytes(packet, 0x0);
        pack_2_bytes(packet, id);
        pack_2_bytes(packet, seq);

	for (i = 0; i < 56; i ++) {
		packet[packet_len + i] = 0xaa;
	}
	packet_len += 56;
	icmp_len = packet_len - ip_len;

	if (cksum == FILL) {
		icmp_checksum = checksum((unsigned short *) (packet + ip_len), icmp_len);

		packet[icmp_checksum_loc] = icmp_checksum & 0xff;
		packet[icmp_checksum_loc + 1] = (icmp_checksum >> 8) & 0xff;
	} else {
		packet[icmp_checksum_loc] = cksum & 0xff;
		packet[icmp_checksum_loc + 1] = (cksum >> 8) & 0xff;
	}

	
        *len = *len + packet_len - ip_len;
}

